package org.jeecg.modules.business.rlzy.vo;

import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.codec.Base64;
import org.springframework.util.DigestUtils;

import java.util.SortedMap;
import java.util.TreeMap;

/**
 * @Program: aj-nmg-px
 * @Description:
 * @Author: liuye
 * @Create: 2023-04-26 14:42
 * @Version 1.0
 */
public class Test {
    public static void main(String[] args) {

// Java生成X-Sign
        long timeStamp = System.currentTimeMillis();
        String appId = "ff80808184efd1250184efd125570000";
        String appSecret = "ff80808184efd1250184efd125570001";
        String nonce = RandomUtil.randomString(10);
        System.out.println("timeStamp: " + timeStamp);
        System.out.println("appId: " + appId);
        System.out.println("nonce: " + nonce);
        SortedMap sortedMap = new TreeMap();
        sortedMap.put("X-APPID", appId);
        sortedMap.put("X-TIMESTAMP", String.valueOf(timeStamp));
        sortedMap.put("X-Nonce", nonce);

// 1. 先将参数转换成json字符串
        String paramsJsonStr = JSONObject.toJSONString(sortedMap);
        System.out.println(paramsJsonStr);
// 2. 先将数据进行md5加密
        String data = DigestUtils.md5DigestAsHex((paramsJsonStr + appSecret).getBytes());
        System.out.println(data);
// 3. 转换成大写
        data = data.toUpperCase();
        System.out.println(data);
// 4. 进行base64编码
        String x_sign = Base64.encodeToString(data.getBytes());

        System.out.println(x_sign);

        // String auth = MD5Util.MD5Encode() ;
       // System.out.println(); hSrGa7GC5Ib2OwaxCUR69KhLUuCRR6GR
    }
}
